package com.gxpt.app.view;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TextView;

import com.google.gson.Gson;
import com.gxpt.app.AppUtils;
import com.gxpt.app.BaseActivity;
import com.gxpt.app.Constant;
import com.gxpt.app.MessageEvent;
import com.gxpt.app.R;
import com.gxpt.app.bean.login_bean;
import com.utils.T;
import com.utils.logger.Logger;
import com.utils.okhttputils.HttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import okhttp3.Call;

/**
 * Created by dufeng on 2017/8/4.
 */

@ContentView(R.layout.activity_pay_show_life)
public class Activity_pay_show_life extends BaseActivity {

    @ViewInject(R.id.toback)
    Button toback;

    @ViewInject(R.id.txt_title)
    TextView txt_title;

    @ViewInject(R.id.toPay)
    Button toPay;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        initView();
    }

    @Override
    public void initView() {
        txt_title.setText(getString(R.string.txt_zhifufangshi));
    }




    @Override
    public void initData() {

    }

    @Event(value={R.id.toback,R.id.toPay})
    private void getEvent(View view){
        switch(view.getId()){

            case R.id.toback:
                closeActivity();
                break;
            case R.id.toPay:

                break;

        }
    }


    //////NET DO
    StringCallback do_login = new StringCallback(){


        @Override
        public void onError(Call call, Exception e, int i) {
            Logger.e(e.getMessage());
        }

        @Override
        public void onResponse(String s, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
            Logger.e(s);
            try{
                login_bean data = new Gson().fromJson(s, login_bean.class);
                if(data.state !=1 ){
                    T.show(context,data.msg,0);
                }else{
                    AppUtils.putXML_user(data.data,context);
                    EventBus.getDefault().post(new MessageEvent(Constant.ACTION_refresh_center));
                    closeActivity();
                }
            }catch (Exception e){
                e.printStackTrace();
                T.show(context,getResources().getString(R.string.alert_again),0);
            }
        }
    };

    /////NET
    private void toNet_login(){
        hud.show();
        JSONObject jsonBody=new JSONObject();
        try {
            jsonBody.put("device_number",         AppUtils.get_device_id(context));
            jsonBody.put("device_type",           Constant.device_type);
            jsonBody.put("token",                 AppUtils.get_token(context));
            jsonBody.put("pageName",             "member");
            jsonBody.put("serviceName",          "login");

//            jsonBody.put("mem_tel",          put_phone.getText().toString());
//            jsonBody.put("mem_pwd",          put_pwd.getText().toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        HttpUtils.http_post_string(Constant.URL_login,jsonBody.toString(),do_login);
    }
}
